<template>
  <!-- 折线图 -->
  <div class="cbox" :style="`width: ${width};height:${height}`">
    <div class="two" ref="two"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  props: {
    legendTop: {
      type: String,
      default: "4%"
    },

    legendData: {
      type: Array,
      default: () => {
        return ["模拟数据1", "模拟数据2"];
      },
    },

    xAxisData: {
      type: Array,
      default: () => {
        return ["a", "b", "c", "d", "e"];
      },
    },

    seriesData: {
      type: Array,
      default: () => {
        return [
          {
            name: "模拟数据1",
            type: "line",

            smooth: true, // 平滑曲线显示
            symbolSize: 3,
            symbol: "circle",
            itemStyle: {
              color: "#00c0e9",
            },
            markPoint: {
              label: {
                normal: {
                  textStyle: {
                    color: "#fff",
                  },
                },
              },
              data: [
                {
                  type: "max",
                  name: "最大值",
                },
                {
                  type: "min",
                  name: "最小值",
                },
              ],
            },
            markLine: {
              label: {
                show: true,
                color: "#FFF",
              },
              data: [{ type: "average", name: "Avg" }],
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "RGBA(0,192,233,0.5)",
                },
                {
                  offset: 1,
                  color: "RGBA(0,192,233,0)",
                },
              ]),
            },
            data: [100, 200, 660, 52, 40, 80],
          },
          {
            name: "模拟数据2",
            type: "line",
            smooth: true, // 平滑曲线显示
            symbolSize: 3,
            symbol: "circle",
            itemStyle: {
              color: "#0096f3",
            },
            markPoint: {
              label: {
                normal: {
                  textStyle: {
                    color: "#fff",
                  },
                },
              },
              data: [
                {
                  type: "max",
                  name: "最大值",
                },
                {
                  type: "min",
                  name: "最小值",
                },
              ],
            },
            markLine: {
              label: {
                show: true,
                color: "#FFF",
              },
              data: [{ type: "average", name: "Avg" }],
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "RGBA(0,150,243,0.5)",
                },
                {
                  offset: 1,
                  color: "RGBA(0,150,243,0)",
                },
              ]),
            },
            data: [200, 320, 150, 260, 190],
          },
        ];
      },
    },

    width: {
      type: String,
      default: "800px",
    },

    height: {
      type: String,
      default: "700px",
    },
  },
  data() {
    return {};
  },
  methods: {
    initChart() {
      const myChart = echarts.init(this.$refs.two);
      myChart.setOption(this.pieOption);
      //  const { proxy } = getCurrentInstance();
    },
  },
  mounted() {
    this.initChart();
  },
  updated() {
    this.initChart();
  },
  computed: {
    pieOption() {
      return {
        backgroundColor: "transparent",
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            textStyle: {
              color: "#fff",
            },
          },
        },
        grid: {
          borderWidth: 0,
          top: 75,
          left: 50,
          right: 70,
          bottom: 95,
          textStyle: {
            color: "#fff",
          },
        },
        legend: {
          right: "1.5%",
          top: this.legendTop,
          textStyle: {
            color: "#90979c",
          },
          data: this.legendData,
        },
        calculable: true,
        toolbox: {
          iconStyle: {
            // color: "#fff",
            borderColor: "#CCC",
          },
          // top: "1%",
          right: "1.5%",
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: "none",
            },
            dataView: { readOnly: false },
            magicType: { type: ["line", "bar"] },
            restore: {},
            saveAsImage: {},
          },
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              lineStyle: {
                color: "rgba(204,187,225,0.5)",
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "rgba(77, 128, 254, 0.2)",
                width: 2,
              },
            },
            axisTick: {
              show: false,
            },
            data: this.xAxisData,
          },
        ],
        yAxis: [
          {
            type: "value",
            splitLine: {
              show: true,
              lineStyle: {
                color: "rgba(77, 128, 254, 0.2)",
                width: 2,
              },
            },
            axisLine: {
              lineStyle: {
                color: "rgba(204,187,225,0.5)",
              },
            },
          },
        ],
        dataZoom: [
          {
            show: true,
            height: 25,
            xAxisIndex: [0],
            bottom: 18,
            start: 0,
            end: 100,
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5",
            },
            textStyle: {
              color: "#fff",
            },
            fillerColor: "rgba(77, 128, 254, 0.2)",
            borderColor: "#90979c",
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 1,
            end: 35,
          },
        ],
        series: this.seriesData,
      };
    },
  },
};
</script>

<style lang="less" scoped>
.cbox {
  // width: 600px;
  // height: 600px;
}

.two {
  width: 100%;
  height: 100%;
}
</style>
